import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';
import 'package:shen_nai/routes/app_routes.dart';
import 'package:shen_nai/socket/socket_server_manage.dart';

import 'app/user_controller.dart';
import 'config/app_colors.dart';

//app入口
void main() {
  WidgetsFlutterBinding.ensureInitialized(); //不加这个强制横/竖屏会报错
  SystemChrome.setPreferredOrientations([
    // 强制竖屏
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]);
  runApp(const MyApp());
  SystemUiOverlayStyle light = const SystemUiOverlayStyle(
    systemNavigationBarColor: Color(0xFF000000),
    systemNavigationBarDividerColor: null,
    statusBarColor: null,
    systemNavigationBarIconBrightness: Brightness.light,
    statusBarIconBrightness: Brightness.light,
    statusBarBrightness: Brightness.dark,
  );
  SystemChrome.setSystemUIOverlayStyle(light);
}

//app配置
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      builder: EasyLoading.init(),
      onInit: () {
        Get.put(UserController());
        SocketServerManage().connectSocket();
      },
      theme: ThemeData(
          primarySwatch: Colors.blue,
          primaryColor: AppColors.primary, // 主题色
          scaffoldBackgroundColor: AppColors.page, // 脚手架下的页面背景色
          indicatorColor: AppColors.active, // 选项卡栏中所选选项卡指示器的颜色。
          splashColor: Colors.transparent, //取消按钮水波纹效果
          highlightColor: Colors.transparent, //取消按钮水波纹效果
          tabBarTheme: const TabBarTheme(
            unselectedLabelColor: AppColors.unactive,
            labelColor: AppColors.primary,
            indicatorSize: TabBarIndicatorSize.label,
            labelStyle: TextStyle(
              fontSize: 14,
            ),
            labelPadding: EdgeInsets.symmetric(horizontal: 12),
          ),
          bottomNavigationBarTheme: const BottomNavigationBarThemeData(
              backgroundColor: Color(0xff0C0919),
              selectedItemColor: Color(0xff3689F7),
              unselectedItemColor: Color(0xffCBD5F9),
              selectedLabelStyle: TextStyle(
                fontSize: 11,
              ),
              unselectedLabelStyle: TextStyle(
                fontSize: 11,
              ))),
      getPages: AppRoute.routerList,
      initialRoute: AppRoute.WELCOME,
      localizationsDelegates: GlobalMaterialLocalizations.delegates,
      supportedLocales: const [
        //此处
        Locale('zh', 'CH'),
        Locale('en', 'US'),
      ],
      locale: const Locale('zh', 'CH'),
    );
  }
}
